package com.sgb.kjwl.view.ui.activity.leaseAsk;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.CompoundButton;

import androidx.databinding.DataBindingUtil;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityLeaseAskQueaEditBinding;
import com.sgb.kjwl.di.machine.DaggerMachineComponent;
import com.sgb.kjwl.di.machine.MachineModule;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.lease.AskLeaseItemEntity;
import com.sgb.kjwl.model.entity.lease.AskLeaseSheBeiEntity3;
import com.sgb.kjwl.model.entity.lease.RentAddressBean;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.sgb.kjwl.viewmodel.machine.AskLeasePubEditModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.MToast;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;

import javax.inject.Inject;

@Deprecated
public class AskLeasePubEditActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    @Inject
    AskLeasePubEditModel viewModel;

    ActivityLeaseAskQueaEditBinding binding;

    // 一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    // 二级联动数据
    private List<List<AddressEntity<List<AddressEntity>>>> opt2;
    // 三级联动数据
    private List<List<List<AddressEntity>>> opt3;
    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;
    private Calendar selectedDate;

    private int type = 0;
    private String id = "";
    private List<PickSelectEntity> classDatas;
    private List<List<PickSelectEntity>> typeDatas;
    private List<PickSelectEntity> driverDatas;
    private List<PickSelectEntity> limitTimeDatas;
    private List<PickSelectEntity> payDatas;
    private List<PickSelectEntity> timeUnitDatas;
    private List<PickSelectEntity> priceUnitDatas;
    private List<PickSelectEntity> priceMatchUnitDatas;
    private UserMsgEntity userMsgEntity;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerMachineComponent.builder().appComponent(appComponent)
                .machineModule(new MachineModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context,int type) {
        Intent intent = new Intent(context, AskLeasePubEditActivity.class);
        intent.putExtra("type",type);
        context.startActivity(intent);
    }

    public static void start(Context context,int type,String id) {
        Intent intent = new Intent(context, AskLeasePubEditActivity.class);
        intent.putExtra("type",type);
        intent.putExtra("id",id);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_lease_ask_quea_edit);
        binding.setViewModel(viewModel);
        binding.backView.setOnClickListener(v -> finish());
        binding.itemTvClass.setOnWholeItemClickListener(this);
        binding.itemTvAddr.setOnWholeItemClickListener(this);
        binding.itemTvTime.setOnWholeItemClickListener(this);
        binding.itemTvDriver.setOnWholeItemClickListener(this);
        binding.itemTvLimitTime.setOnWholeItemClickListener(this);
        binding.itemTvPay.setOnWholeItemClickListener(this);
//        binding.layoutDays.setOnClickListener(v -> showTimeUnitPop());
        binding.layoutPrice.setOnClickListener(v -> {
//            if(type == 0){
//                showMatchPriceUnitPop();
//            }else if(type == 1){
                showPriceUnitPop();
//            }
        });

        binding.publicView.setOnClickListener(v -> pubDevice());

        binding.itemTvNum.setInputType(InputType.TYPE_CLASS_NUMBER);
        binding.itemTvPrice.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        binding.itemTvContactsNumber.setInputType(InputType.TYPE_CLASS_PHONE);

        binding.rbTime.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    binding.rbTime.setButtonDrawable(R.mipmap.lease_pub_select);
                    binding.layoutDays.setVisibility(View.GONE);
                    binding.rbTime.setText("您已选择面议，再次点击退出面议");
                }else{
                    binding.rbTime.setButtonDrawable(R.mipmap.lease_pub_unselect);
                    binding.layoutDays.setVisibility(View.VISIBLE);
                    binding.rbTime.setText("面议");
                }
            }
        });

        binding.rbPrice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    binding.rbPrice.setButtonDrawable(R.mipmap.lease_pub_select);
                    binding.layoutPrice.setVisibility(View.GONE);
                    binding.rbPrice.setText("您已选择面议，再次点击退出面议");
                }else{
                    binding.rbPrice.setButtonDrawable(R.mipmap.lease_pub_unselect);
                    binding.layoutPrice.setVisibility(View.VISIBLE);
                    binding.rbPrice.setText("面议");
                }
            }
        });
    }

    @Override
    protected void init() {
        type = getIntent().getIntExtra("type",0);
        id = getIntent().getStringExtra("id");

//        if(!TextUtils.isEmpty(id)){
//            if(type == 0){
//                viewModel.getMatchDetail(id);
//            }else if(type == 1){
//                viewModel.getDeviceDetail(id,String.valueOf(type));
//            }
//        }

        opt2 = new ArrayList<>();
        opt3 = new ArrayList<>();
        classDatas = new ArrayList<>();
        typeDatas = new ArrayList<>();
        driverDatas = new ArrayList<>();
        limitTimeDatas = new ArrayList<>();
        payDatas = new ArrayList<>();
        timeUnitDatas = new ArrayList<>();
        priceUnitDatas = new ArrayList<>();
        priceMatchUnitDatas = new ArrayList<>();

        selectedDate = Calendar.getInstance();

        //分类列表
        viewModel.getTypeModel();
        viewModel.getAddressModel();

        //是否带驾驶员（0:是;1:否）
        PickSelectEntity dentity = new PickSelectEntity();
        dentity.setNo("0");
        dentity.setProjectscale("是");
        PickSelectEntity dentity1 = new PickSelectEntity();
        dentity1.setNo("1");
        dentity1.setProjectscale("否");
        driverDatas.add(dentity);
        driverDatas.add(dentity1);

        for(int i=1;i<30;i++){
            PickSelectEntity timedentity = new PickSelectEntity();
            timedentity.setNo(""+i);
            timedentity.setProjectscale(i+"天");
            limitTimeDatas.add(timedentity);
        }

        String[] pays = new String[]{"预付","结束后付","协商付款"};
        for(int i=1;i<4;i++){
            PickSelectEntity paydentity = new PickSelectEntity();
            paydentity.setNo(""+i);
            paydentity.setProjectscale(pays[i-1]);
            payDatas.add(paydentity);
        }

        String[] timeUnit = new String[]{"天","月","年"};
        for(int i=1;i<4;i++){
            PickSelectEntity timedentity = new PickSelectEntity();
            timedentity.setNo(""+i);
            timedentity.setProjectscale(timeUnit[i-1]);
            timeUnitDatas.add(timedentity);
        }

        String[] priceUnit = new String[]{"元/台班","元/天"};
        for(int i=1;i<3;i++){
            PickSelectEntity timedentity = new PickSelectEntity();
            timedentity.setNo(""+i);
            timedentity.setProjectscale(priceUnit[i-1]);
            priceUnitDatas.add(timedentity);
        }

        String[] priceMatchUnit = new String[]{"台","辆"};
        for(int i=1;i<3;i++){
            PickSelectEntity timedentity = new PickSelectEntity();
            timedentity.setNo(""+i);
            timedentity.setProjectscale(priceMatchUnit[i-1]);
            priceMatchUnitDatas.add(timedentity);
        }

        if(type == 0){
            binding.tvTitle.setText("机械求租");
//            binding.tvPriceUnit.setText("台");
            viewModel.addDeviceEntity1.get().setRentalSelectPrice("2");
        }else if(type == 1){
            binding.tvTitle.setText("设备求租");
            binding.itemTvDriver.setVisibility(View.GONE);
//            binding.tvPriceUnit.setText("元/天");
            viewModel.addDeviceEntity1.get().setRentalSelectPrice("2");
        }


        viewModel.getUserInfo();
    }

    @Override
    public void OnWholeItemClick(View view) {
        switch (view.getId()) {
            case R.id.item_tv_class:
                showClassTypePop();
                break;
            case R.id.item_tv_addr:
                if (addressEntityList != null) {
                    showCityPop("请选择地区");
                }
                break;
            case R.id.item_tv_time:
                showTimePop();
                break;
            case R.id.item_tv_driver:
                if(null!=driverDatas && driverDatas.size()>0){
                    showDriverPop();
                }
                break;
            case R.id.item_tv_limit_time:
                if(null!=limitTimeDatas && limitTimeDatas.size()>0){
                    showLimitTimePop();
                }
                break;
            case R.id.item_tv_pay:
                if(null!=payDatas && payDatas.size()>0){
                    showPayPop();
                }
                break;
        }
    }

    private void pubDevice(){
        if (TextUtils.isEmpty(binding.itemTvClass.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请选择分类");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvAddr.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请选择地区");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvTime.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请选择时间");
            return;
        } else if (type == 0 && TextUtils.isEmpty(binding.itemTvDriver.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请选择驾驶员类型");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvNum.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请输入租赁数量");
            return;
        } else if (!binding.rbTime.isChecked() && TextUtils.isEmpty(binding.itemTvDays.getText().toString())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请输入租赁时长");
            return;
        } else if (!binding.rbPrice.isChecked() && TextUtils.isEmpty(binding.itemTvPrice.getText().toString())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请输入租赁价格");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvLimitTime.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请选择报价期限");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvPay.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请选择付款方式");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvContacts.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请输入联系人");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvContactsNumber.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请输入联系电话");
            return;
        } else if (!CheckUtils.isMobileNum(binding.itemTvContactsNumber.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请输入正确手机格式");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvTitle.getContent())) {
            MToast.showToast(AskLeasePubEditActivity.this, "请输入标题");
            return;
        }

        if(TextUtils.isEmpty(binding.cfkEdit.getEditContent())){
            viewModel.addDeviceEntity1.get().setRemark("");
        }else{
            viewModel.addDeviceEntity1.get().setRemark(binding.cfkEdit.getEditContent());
        }

        if(binding.rbTime.isChecked()){
            viewModel.addDeviceEntity1.get().setRentalDuration("-1");
        }

        if(binding.rbPrice.isChecked()){
            viewModel.addDeviceEntity1.get().setRentalPrice("-1");
        }

        if(null!=userMsgEntity){
            viewModel.addDeviceEntity1.get().setCreateUserName(userMsgEntity.getRealName());
            viewModel.addDeviceEntity1.get().setCreateUserNo(userMsgEntity.getNo());
            viewModel.addDeviceEntity1.get().setCreateCompanyNo(userMsgEntity.getCurrentIdentityNo());
            viewModel.addDeviceEntity1.get().setCreateCompanyName(userMsgEntity.getCurrentIdentityName());
        }

        viewModel.addDeviceEntity1.get().setRentalUnit("1");
        viewModel.addDeviceEntity1.get().setRentalDurationUnit("0");

        //"预付","结束后付","协商付款"
        if(viewModel.addDeviceEntity1.get().getRentalPayMethod().equals("预付")){
            viewModel.addDeviceEntity1.get().setRentalPayMethod("1");
        }else if(viewModel.addDeviceEntity1.get().getRentalPayMethod().equals("结束后付")){
            viewModel.addDeviceEntity1.get().setRentalPayMethod("2");
        }else if(viewModel.addDeviceEntity1.get().getRentalPayMethod().equals("协商付款")){
            viewModel.addDeviceEntity1.get().setRentalPayMethod("3");
        }

        //"元/台班","元/天"
        if(viewModel.addDeviceEntity1.get().getRentalSelectPrice().equals("元/台班")){
            viewModel.addDeviceEntity1.get().setRentalSelectPrice("1");
        }else if(viewModel.addDeviceEntity1.get().getRentalSelectPrice().equals("元/天")){
            viewModel.addDeviceEntity1.get().setRentalSelectPrice("2");
        }

        if(type == 0){
            viewModel.pubMatchData();
        }else if(type == 1){
            viewModel.pubDeviceData();
        }
    }

    public void showTypeView(List<AskLeaseItemEntity<List<AskLeaseItemEntity<List<AskLeaseItemEntity>>>>> datas) {
        if (datas == null || datas.size() == 0) {
            return;
        }

        if(type == 0){//机械
            for(AskLeaseItemEntity<List<AskLeaseItemEntity>> l : datas.get(0).getChildren()){
                PickSelectEntity entity = new PickSelectEntity();
                entity.setNo(l.getNo());
                entity.setProjectscale(l.getName());
                classDatas.add(entity);

                List<PickSelectEntity> childList = new ArrayList<>();
                for(AskLeaseItemEntity ll: l.getChildren()){
                    PickSelectEntity child = new PickSelectEntity();
                    child.setNo(ll.getNo());
                    child.setProjectscale(ll.getName());
                    childList.add(child);
                }
                typeDatas.add(childList);
            }
        }else if(type == 1){//设备
            for(AskLeaseItemEntity<List<AskLeaseItemEntity>> l : datas.get(1).getChildren()){
                PickSelectEntity entity = new PickSelectEntity();
                entity.setNo(l.getNo());
                entity.setProjectscale(l.getName());
                classDatas.add(entity);

                List<PickSelectEntity> childList = new ArrayList<>();
                for(AskLeaseItemEntity ll: l.getChildren()){
                    PickSelectEntity child = new PickSelectEntity();
                    child.setNo(ll.getNo());
                    child.setProjectscale(ll.getName());
                    childList.add(child);
                }
                typeDatas.add(childList);
            }
        }
    }
    public void showDetail(AskLeaseSheBeiEntity3 detailEditEntity){
        if(null==detailEditEntity)
            return;
        viewModel.addDeviceEntity1.set(detailEditEntity);
        if(detailEditEntity.getIsDriver() == 0){
            binding.itemTvDriver.setContent("是");
        }else{
            binding.itemTvDriver.setContent("否");
        }

        if(!TextUtils.isEmpty(detailEditEntity.getRentalQuotePeriod())){
            binding.itemTvLimitTime.setContent(detailEditEntity.getRentalQuotePeriod()+"天");
        }

        if (detailEditEntity.getRentalPrice().equals("-1") || detailEditEntity.getRentalPrice().equals("-1.0")) {
            binding.rbPrice.setChecked(true);
            binding.layoutPrice.setVisibility(View.GONE);
        } else {
            binding.itemTvPrice.setText(detailEditEntity.getRentalPrice());
            binding.tvPriceUnit.setText(detailEditEntity.getRentalSelectPrice());
        }

        if (detailEditEntity.getRentalDuration().equals("-1")) {
            binding.rbTime.setChecked(true);
            binding.layoutDays.setVisibility(View.GONE);
        } else {
            binding.itemTvDays.setText(detailEditEntity.getRentalDuration());
        }

        binding.cfkEdit.setEditContent(detailEditEntity.getRemark());
    }
//    public void showDetail(AskLeaseDetailEditEntity detailEditEntity){
//        if(null==detailEditEntity.getRentSeek())
//            return;
//        viewModel.addDeviceEntity1.set(detailEditEntity.getRentSeek());
//
//        if(detailEditEntity.getRentSeek().getIsDriver() == 0){
//            binding.itemTvDriver.setContent("是");
//        }else{
//            binding.itemTvDriver.setContent("否");
//        }
//
//        if(!TextUtils.isEmpty(detailEditEntity.getRentSeek().getRentalQuotePeriod())){
//            binding.itemTvLimitTime.setContent(detailEditEntity.getRentSeek().getRentalQuotePeriod()+"天");
//        }
//
//        if (detailEditEntity.getRentSeek().getRentalPrice().equals("-1") || detailEditEntity.getRentSeek().getRentalPrice().equals("-1.0")) {
//            binding.rbPrice.setChecked(true);
//            binding.layoutPrice.setVisibility(View.GONE);
//        } else {
//            binding.itemTvPrice.setText(detailEditEntity.getRentSeek().getRentalPrice());
//            binding.tvPriceUnit.setText(detailEditEntity.getRentSeek().getRentalSelectPrice());
//        }
//
//        if (detailEditEntity.getRentSeek().getRentalDuration().equals("-1")) {
//            binding.rbTime.setChecked(true);
//            binding.layoutDays.setVisibility(View.GONE);
//        } else {
//            binding.itemTvDays.setText(detailEditEntity.getRentSeek().getRentalDuration());
//        }
//
//        binding.cfkEdit.setEditContent(detailEditEntity.getRentSeek().getRemark());
//    }

    public void displayRole(UserMsgEntity data) {
        userMsgEntity = data;
    }

    private void showClassTypePop() {
        OptionsPickerView businessOption = new OptionsPickerBuilder(AskLeasePubEditActivity.this, (options1, options2, options3, v) -> {
            String className = classDatas.get(options1).getProjectscale();
            String typeName = typeDatas.get(options1).get(options2).getProjectscale();
            binding.itemTvClass.setContent(className + " " +typeName);
            binding.itemTvTitle.setContent(className + " " +typeName);

            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setCategoryType(type);
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setCategoryParentId(classDatas.get(options1).getNo());
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setCategoryChildId(typeDatas.get(options1).get(options2).getNo());

            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setCategoryName(type==0?"工程机械":"工程设备");
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setCategoryParentName(classDatas.get(options1).getProjectscale());
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setCategoryChildName(typeDatas.get(options1).get(options2).getProjectscale());

        }).build();
        businessOption.setPicker(classDatas,typeDatas);
        businessOption.setSelectOptions(0,0);
        businessOption.show();
    }

    private void showDriverPop() {
        OptionsPickerView businessOption = new OptionsPickerBuilder(AskLeasePubEditActivity.this, (options1, options2, options3, v) -> {
            String content = driverDatas.get(options1).getProjectscale();
            binding.itemTvDriver.setContent(content);
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setIsDriver(Integer.parseInt(driverDatas.get(options1).getNo()));
        }).build();
        businessOption.setPicker(driverDatas);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    private void showLimitTimePop() {
        OptionsPickerView businessOption = new OptionsPickerBuilder(AskLeasePubEditActivity.this, (options1, options2, options3, v) -> {
            String content = limitTimeDatas.get(options1).getProjectscale();
            binding.itemTvLimitTime.setContent(content);
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setRentalQuotePeriod(limitTimeDatas.get(options1).getNo());
        }).build();
        businessOption.setPicker(limitTimeDatas);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    private void showPayPop() {
        OptionsPickerView businessOption = new OptionsPickerBuilder(AskLeasePubEditActivity.this, (options1, options2, options3, v) -> {
            String content = payDatas.get(options1).getProjectscale();
            binding.itemTvPay.setContent(content);
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setRentalPayMethod(payDatas.get(options1).getNo());
        }).build();
        businessOption.setPicker(payDatas);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    private void showTimeUnitPop(){
        OptionsPickerView businessOption = new OptionsPickerBuilder(AskLeasePubEditActivity.this, (options1, options2, options3, v) -> {
            String content = timeUnitDatas.get(options1).getProjectscale();
            binding.tvTimeUnit.setText(content);
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setRentalDurationUnit(timeUnitDatas.get(options1).getProjectscale());
        }).build();
        businessOption.setPicker(timeUnitDatas);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    private void showPriceUnitPop(){
        OptionsPickerView businessOption = new OptionsPickerBuilder(AskLeasePubEditActivity.this, (options1, options2, options3, v) -> {
            String content = priceUnitDatas.get(options1).getProjectscale();
            binding.tvPriceUnit.setText(content);
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setRentalSelectPrice(priceUnitDatas.get(options1).getNo());
        }).build();
        businessOption.setPicker(priceUnitDatas);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    private void showMatchPriceUnitPop(){
        OptionsPickerView businessOption = new OptionsPickerBuilder(AskLeasePubEditActivity.this, (options1, options2, options3, v) -> {
            String content = priceMatchUnitDatas.get(options1).getProjectscale();
            binding.tvPriceUnit.setText(content);
            Objects.requireNonNull(viewModel.addDeviceEntity1.get()).setRentalSelectPrice(priceMatchUnitDatas.get(options1).getNo());
        }).build();
        businessOption.setPicker(priceMatchUnitDatas);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    private void showTimePop(){
        TimePickerView timePicker = new TimePickerBuilder(AskLeasePubEditActivity.this, (date, v) -> {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String format = sdf.format(date);
            try {
                binding.itemTvTime.setContent(format);
                viewModel.addDeviceEntity1.get().setUseAndEnterTime(format);
                selectedDate.setTime(date);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择时间")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .setRangDate(Calendar.getInstance(),null)
                .build();
        timePicker.show();
        timePicker.setDate(selectedDate);

    }

    public void initAddressData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> datas) {
        addressEntityList = datas;
        initJsonData();
    }

    private void showCityPop(String title) {
        CityPickView cityOption = new CityPickBuilder(AskLeasePubEditActivity.this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                String areaName = "";
                if (opt3.get(options1).get(options2).get(options3) == null) {
                    areaName = "";
                } else {
                    areaName = opt3.get(options1).get(options2).get(options3).getName();
                    cityPosition3 = options3;
                }
                String content = addressEntityList.get(options1).getName() + opt2.get(options1).get(options2).getName() + areaName;
                cityPosition1 = options1;
                cityPosition2 = options2;

                RentAddressBean addressBean = new RentAddressBean();
                if(!TextUtils.isEmpty(areaName)){
                    addressBean.setAreaId(opt3.get(options1).get(options2).get(options3).getNo());
                }
                addressBean.setProvinceId(addressEntityList.get(options1).getId());
                addressBean.setCityId(opt2.get(options1).get(options2).getNo());
                addressBean.setRentalAddress(content);
                viewModel.addDeviceEntity1.get().setRentAddress(addressBean);
                binding.itemTvAddr.setContent(content);
            }
        }).setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText(title)
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .build();
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.show();
    }

    private void initJsonData() {

        for (int i = 0; i < addressEntityList.size(); i++) {

//            cityList = new ArrayList<>();
            ArrayList areaList = new ArrayList<>();
            opt2.add(addressEntityList.get(i).getChildren());
            for (int j = 0; j < addressEntityList.get(i).getChildren().size(); j++) {

                List<AddressEntity> cityAreaList = new ArrayList<>();
                List<AddressEntity> children = addressEntityList.get(i).getChildren().get(j).getChildren();
                if (children == null || children.size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(children);
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }

    }
}
